import request from './request'

// 项目API统一导出
export const projectAPI = {
  // 纵向课题相关API
  getVerticalProjects(params) {
    return request({
      url: '/vertical-projects',
      method: 'get',
      params
    })
  },

  getVerticalProject(id) {
    return request({
      url: `/vertical-projects/${id}`,
      method: 'get'
    })
  },

  createVerticalProject(data) {
    return request({
      url: '/vertical-projects',
      method: 'post',
      data
    })
  },

  updateVerticalProject(id, data) {
    return request({
      url: `/vertical-projects/${id}`,
      method: 'put',
      data
    })
  },

  deleteVerticalProject(id) {
    return request({
      url: `/vertical-projects/${id}`,
      method: 'delete'
    })
  },

  // 横向课题相关API
  getHorizontalProjects(params) {
    return request({
      url: '/horizontal-projects',
      method: 'get',
      params
    })
  },

  getHorizontalProject(id) {
    return request({
      url: `/horizontal-projects/${id}`,
      method: 'get'
    })
  },

  createHorizontalProject(data) {
    return request({
      url: '/horizontal-projects',
      method: 'post',
      data
    })
  },

  updateHorizontalProject(id, data) {
    return request({
      url: `/horizontal-projects/${id}`,
      method: 'put',
      data
    })
  },

  deleteHorizontalProject(id) {
    return request({
      url: `/horizontal-projects/${id}`,
      method: 'delete'
    })
  }
}

// 纵向课题API (保持向后兼容)
export const verticalProjectAPI = {
  // 获取所有纵向课题
  getAll(params) {
    return projectAPI.getVerticalProjects(params)
  },

  // 获取我的纵向课题
  getMy() {
    return request({
      url: '/vertical-projects/my',
      method: 'get'
    })
  },

  // 根据ID获取纵向课题
  getById(id) {
    return projectAPI.getVerticalProject(id)
  },

  // 创建纵向课题
  create(data) {
    return projectAPI.createVerticalProject(data)
  },

  // 更新纵向课题
  update(id, data) {
    return projectAPI.updateVerticalProject(id, data)
  },

  // 删除纵向课题
  delete(id) {
    return projectAPI.deleteVerticalProject(id)
  },

  // 根据审核状态查询
  getByAuditStatus(status) {
    return request({
      url: `/vertical-projects/audit-status/${status}`,
      method: 'get'
    })
  },

  // 条件查询
  search(params) {
    return request({
      url: '/vertical-projects/search',
      method: 'get',
      params
    })
  },

  // 提交审核
  submit(id) {
    return request({
      url: `/vertical-projects/${id}/submit`,
      method: 'post'
    })
  }
}

// 横向课题API (保持向后兼容)
export const horizontalProjectAPI = {
  // 获取所有横向课题
  getAll(params) {
    return projectAPI.getHorizontalProjects(params)
  },

  // 获取我的横向课题
  getMy() {
    return request({
      url: '/horizontal-projects/my',
      method: 'get'
    })
  },

  // 根据ID获取横向课题
  getById(id) {
    return projectAPI.getHorizontalProject(id)
  },

  // 创建横向课题
  create(data) {
    return projectAPI.createHorizontalProject(data)
  },

  // 更新横向课题
  update(id, data) {
    return projectAPI.updateHorizontalProject(id, data)
  },

  // 删除横向课题
  delete(id) {
    return projectAPI.deleteHorizontalProject(id)
  },

  // 根据审核状态查询
  getByAuditStatus(status) {
    return request({
      url: `/horizontal-projects/audit-status/${status}`,
      method: 'get'
    })
  },

  // 条件查询
  search(params) {
    return request({
      url: '/horizontal-projects/search',
      method: 'get',
      params
    })
  },

  // 提交审核
  submit(id) {
    return request({
      url: `/horizontal-projects/${id}/submit`,
      method: 'post'
    })
  }
}
